<?php

function strip_colors($text){
	return preg_replace('#\x03(?:\d?\d?(?:,\d?\d?)?)?#', '', $text);
}

function dirlist($path,$incPath=false){
  $fList=Array();
  if (!$path) die();
  if ($handle = opendir($path)) {
    while (false !== ($file = readdir($handle))) {
      if ($file != '.') {
          if($incPath){
            $fList[]=$path.$file;
          } else {
            $fList[]=$file;
          }
      }
    }
    closedir($handle);
  }
  return $fList;
}

function system_o($cmd){
  exec("$cmd", $f);
  foreach($f as $output) {
  $output = htmlentities($output);
  $ret .= "$output\n";
  }
  return $ret;
}

function padZero($int){
  if($int<10){
    return "0".$int;
  } else {
    return $int;
  }
}

function array_removal($val,&$arr){
  $i=array_search($val,$arr);
  if($i===false)return false;
  $arr=array_merge(array_slice($arr, 0,$i), array_slice($arr, $i+1));
  return true;
}

$colors=Array("");
$colors['white']=0;
$colors['black']=1;
$colors['navy']=2;
$colors['green']=3;
$colors['red']=4;
$colors['darkred']=5;
$colors['purple']=6;
$colors['orange']=7;
$colors['yellow']=8;
$colors['lightgreen']=9;
$colors['bluegreen']=10;
$colors['skyblue']=11;
$colors['blue']=12;
$colors['pink']=13;
$colors['gray']=14;
$colors['lightgray']=15;

function colorText($color,$bgColor,$text){
  global $colors;
  return chr(3).padZero($colors[$color]).",".padZero($colors[$bgColor]).$text;
}

function regex($string,$one,$two,$strip=false){
  if($strip){
    $string=str_replace("\r","",$string);
    $string=str_replace("\n","",$string);
  }
  $textA1=explode($one,$string);
  $textP1=$textA1[1];
  $textA2=explode($two,$textP1);
  $text=$textA2[0];
  return $text;
}

function pluralize($string,$number=""){
  if(!$number){
    $number=$string;
  }
  if($number!=1){
    $string.="s";
  }
  return $string;
}

?>